﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging.Messages;
using CommunityToolkit.Mvvm.Messaging;
using CommunityToolkitMvvmDemo.Models;
using CommunityToolkitMvvmDemo.Servers;
using CommunityToolkitMvvmDemo.UserControls;
using HandyControl.Controls;
using HandyControl.Data;
using HarfBuzzSharp;
using LiveCharts;
using LiveCharts.Wpf;
using LiveChartsCore.Measure;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Xml;
using static System.Net.Mime.MediaTypeNames;
using HC = HandyControl.Controls;

using MessageBox = HandyControl.Controls.MessageBox;
using System.Net;
using System.Xml.Linq;
using HandyControl.Tools.Extension;

namespace CommunityToolkitMvvmDemo.ViewModels
{
    partial class HandyControlViewModel : ObservableObject
    {
        [ObservableProperty]
        private ObservableCollection<Person> persons;

        #region 选项卡相关
        [ObservableProperty]
        private FrameworkElement tabContent;


        [RelayCommand]
        private void TabControl_SelectionChanged(object sender)
        {
            int index = ((System.Windows.Controls.TabControl)sender).SelectedIndex;

            var item = (System.Windows.Controls.TabItem)((System.Windows.Controls.TabControl)sender).SelectedItem;
            var header = item.Header.ToString();

            //zcx 子控件显示

            // 方法1 ：  StudentList  和  StudentForm 都是控件
            //< Grid Margin = "10" >
            //    < Grid.RowDefinitions >
            //        < RowDefinition Height = "1*" />
            //        < RowDefinition Height = "Auto" />
            //    </ Grid.RowDefinitions >
            //    < !--Left-- >
            //    < local:StudentList Width = "300" HorizontalAlignment = "Left" />
            //    < !--Right-- >
            //    < local:StudentForm Width = "200" HorizontalAlignment = "Right" />
            //    < !--Bottom-- >
            //    < TextBox Grid.Row = "1"  Margin = "0,10,0,0"  d: Text = "Name: Tom, Class: A, Phone: 120"   IsReadOnly = "True"  Text = "{Binding Information}" />
            //</ Grid >


            // 方法2
            //switch (index)
            //{
            //    case 0:
            //        this.Tab1.Children.Add(w1);
            //        break;
            //    case 1:
            //        this.Tab2.Children.Add(w2);
            //        break;
            //}

            // 方法3
            Type type = Type.GetType("CommunityToolkitMvvmDemo.UserControls." + header);
            ConstructorInfo cti = type.GetConstructor(System.Type.EmptyTypes);
            TabContent = (FrameworkElement)cti.Invoke(null);

        }
        public record StepModel(string Header, string Content);


        public record TabModel(string Header);
        [ObservableProperty]
        private ObservableCollection<TabModel> tabList;

        #endregion

        #region Tag标签
        public record TagModel(string Header, string Content, bool IsSelected);
        [ObservableProperty]
        private ObservableCollection<TagModel> tagList;
        #endregion

        #region 图表相关
        [ObservableProperty]
        private string[] labels;

        [ObservableProperty]
        private SeriesCollection seriesCollection;

        [ObservableProperty]
        private ChartValues<double> values1;
        [ObservableProperty]
        private ChartValues<double> values2;
        [ObservableProperty]
        private ObservableCollection<string> xLabels;
        #endregion

        #region ComboXBox 相关
        public enum EnumType { None = 0, Launch = 1, Receiving = 2, TwoWay = 3, EIRP = 4, }
        public Array Enums => Enum.GetValues(typeof(EnumType));

        private EnumType currentItem = EnumType.TwoWay;
        public EnumType CurrentItem
        {
            get { return currentItem; }
            set => SetProperty(ref currentItem, value);
        }

        public IEnumerable<KeyValuePair<int, string>> ComboxKYs { get; private set; }

        [ObservableProperty]
        public int selectedMapTypeIndex = (int)(EnumType)Enum.Parse(typeof(EnumType), EnumType.Launch.ToString());

        public partial class EnumTypeClass : ObservableObject
        {
            [ObservableProperty]
            private EnumType itemType;

            public string Name { get { return ItemType.ToString(); } }
        }

        [ObservableProperty]
        private ObservableCollection<EnumTypeClass> comboxClass;

        [ObservableProperty]
        private EnumTypeClass comboxClassItem;


        public List<ComboBoxItemModel<Person>> ComboxPersons { get; set; }

        //[ObservableProperty]
        //private Person selectedPerson;

        private Person selectedPerson;
        public Person SelectedPerson
        {
            get => selectedPerson;
            set
            {
                SetProperty(ref selectedPerson, value);
                MessageBox.Show(value.Name);
            }
        }

        [ObservableProperty]
        public List<Person> personList = new List<Person>();

        [ObservableProperty]
        public Person selctedPerson;

        #endregion

        #region 菜单相关

        [RelayCommand]
        private void SwitchItem()
        {

        }
        [RelayCommand]
        private void SelectItem(object str)
        {
            XmlAttribute attr = str as XmlAttribute;
            string attrValue = attr.Value; // 或者使用 attr.InnerText;
            MessageBox.Show(attrValue);
        }

        #endregion

        #region ItemsControl 相关

        private ObservableCollection<TabBaseViewModel> itemList;
        public ObservableCollection<TabBaseViewModel> ItemList { get => itemList; set => SetProperty(ref itemList, value); }

        [ObservableProperty]
        private object item;

        [RelayCommand]
        void OpenTab(string str)
        {
            switch (str)
            {
                case "设备1":
                    {
                        Item = new Tab1();
                        break;
                    }
                case "设备2":
                    {
                        Item = new Tab2();
                        break;
                    }
                case "设备3":
                    {
                        Item = new Tab3();
                        break;
                    }
                default:
                    break;
            }
        }



        [ObservableProperty]
        private List<RadioButtons> radioButtonList;
        [ObservableProperty]
        private RadioButtons radioButtonSelect;
        [RelayCommand]
        void RadioBtn()
        {
            RadioButtonSelect = RadioButtonList.Where(p => p.IsCheck).First();
        }


        [ObservableProperty]
        private List<CheckButtons> checkButtonsList;
        [ObservableProperty]
        private String checkButtonSelect;

        [RelayCommand]
        void CheckBtn()
        {
            CheckButtonSelect = "";
            if (CheckButtonsList != null && CheckButtonsList.Count > 0)
            {
                CheckButtonSelect = String.Join(",", CheckButtonsList.Where(p => p.IsCheck).Select(l => l.Content).ToList());
            }
        }
        #endregion

        #region 树相关
        [ObservableProperty]
        private List<TreeNode> treeInfo;
        [RelayCommand]
        private void XmlLoaded(object o)
        {
            XmlDataProvider xdp1 = new XmlDataProvider();
            xdp1.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, @"Assets\Files\DepartMent.xml"));
            xdp1.XPath = @"/Department";
            var obj = o as TreeView;
            obj.DataContext = xdp1;
            obj.SetBinding(TreeView.ItemsSourceProperty, new Binding());

        }
        #endregion

        #region 拖到相关
        public void MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Border border = sender as Border;
            DragDrop.DoDragDrop(border, border, DragDropEffects.Copy);
        }

        StackPanel panel = new StackPanel();
        public void BorderMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Border border = sender as Border;
            if (VisualTreeHelper.GetParent(border) is StackPanel)
                panel = (StackPanel)VisualTreeHelper.GetParent(border);

            DragDrop.DoDragDrop(border, border, DragDropEffects.Copy);
        }
        public void canvas_Drop(object sender, DragEventArgs e)
        {
            var data = e.Data.GetData(typeof(Border));
            //canvas.Children.Add(data);//直接这样不可以，因为同一个实例不允许在于两个容器中
            //先在之前的容器中移除，

            var canvas = sender as Canvas;

            if (panel.Children.Contains(data as UIElement))
            {
                panel.Children.Remove(data as UIElement);
                canvas.Children.Add(data as UIElement);
            }


            //获得鼠标相对于canvas的位置
            var point = e.GetPosition((Canvas)sender);
            Canvas.SetLeft(data as UIElement, point.X);
            Canvas.SetTop(data as UIElement, point.Y);
        }

        private Canvas _parentCanvas = null;
        private bool _isDragging = false;
        private Point _mouseCurrentPoint;


        public void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //获得承载Border的父对象
            if (_parentCanvas == null)
                _parentCanvas = (Canvas)VisualTreeHelper.GetParent(sender as Border);

            this._isDragging = true;

            //获得相对于border的坐标
            this._mouseCurrentPoint = e.GetPosition(sender as Border);

            //关键，锁定鼠标即不让鼠标选中其他元素
            (sender as Border).CaptureMouse();
        }

        public void Border_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (_isDragging)
            {
                //关键，取消锁定鼠标
                (sender as Border).ReleaseMouseCapture();

                _isDragging = false;
            }
        }

        public void Border_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isDragging)
            {
                //获得相对于Canvas的坐标
                Point point = e.GetPosition(_parentCanvas);

                (sender as Border).SetValue(Canvas.TopProperty, point.Y - _mouseCurrentPoint.Y);
                (sender as Border).SetValue(Canvas.LeftProperty, point.X - _mouseCurrentPoint.X);
            }
        }

        #endregion

        #region ListBox 相关
        [ObservableProperty]
        private Person currentPerson;


        [RelayCommand]
        void SelectPerson(string name)
        {
            MessageBox.Show(name);
            MessageBox.Show(CurrentPerson.Mail);
        }
        #endregion

        #region ListView 相关
        [RelayCommand]
        void SelectListView(string name)
        {
            MessageBox.Show(name);
        }
        public CollectionView PersonListGroupView { get; set; }
        public CollectionView PersonListSortView { get; set; }

        [ObservableProperty]
        public CollectionView personListSortView111;

        [ObservableProperty]
        public ICollectionView personListSortView222;

        [RelayCommand]
        void HeaderClick111(string name)
        {
            if (PersonListSortView111.SortDescriptions.Count > 0 &&
                PersonListSortView111.SortDescriptions[0].PropertyName == "Age" &&
                PersonListSortView111.SortDescriptions[0].Direction == ListSortDirection.Ascending)
            {
                PersonListSortView111.SortDescriptions.Clear();
                PersonListSortView111.SortDescriptions.Add(new SortDescription("Age", ListSortDirection.Descending));
            }
            else
            {
                PersonListSortView111.SortDescriptions.Clear();
                PersonListSortView111.SortDescriptions.Add(new SortDescription("Age", ListSortDirection.Ascending));
            }
        }
        [RelayCommand]
        void HeaderClick222(string name)
        {
            if (PersonListSortView222.SortDescriptions.Count > 0 &&
                PersonListSortView222.SortDescriptions[0].PropertyName == "Age" &&
                PersonListSortView222.SortDescriptions[0].Direction == ListSortDirection.Ascending)
            {
                PersonListSortView222.SortDescriptions.Clear();
                PersonListSortView222.SortDescriptions.Add(new SortDescription("Age", ListSortDirection.Descending));
            }
            else
            {
                PersonListSortView222.SortDescriptions.Clear();
                PersonListSortView222.SortDescriptions.Add(new SortDescription("Age", ListSortDirection.Ascending));
            }
        }

        public ListCollectionView PersonListView { get; set; }

        private string filterStr;
        public string FilterStr
        {
            get => filterStr;
            set
            {
                SetProperty(ref filterStr, value);
                PersonListView.Refresh();
            }
        }

        private bool Filter(object obj)
        {
            Person person = obj as Person;
            if (person == null) return false;

            if (string.IsNullOrEmpty(FilterStr))
            {
                return true;
            }
            else
            {
                return person.Name.Contains(FilterStr, StringComparison.OrdinalIgnoreCase);
            }
        }

        #endregion

        #region DataGrid 相关
        [RelayCommand]
        private void Delete(int id)
        {
            var model = Persons.FirstOrDefault(i => i.Id == id);
            if (model != null)
            {
                var msg = String.Format("确认删除当前人员-{0}?", model.Name, "操作提示");
                var r = MessageBox.Show(msg, "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
                if (r == MessageBoxResult.OK)
                {
                    Persons.Remove(model);
                }
            }
        }
        [RelayCommand]
        private void Edit(int id)
        {
            var model = Persons.FirstOrDefault(i => i.Id == id);
            if (model != null)
            {
                EditWindow window = new EditWindow(model);
                window.Width = 350;
                window.Height = 300;
                var ret = window.ShowDialog();
                if (ret.Value)
                {
                    var p = Persons.FirstOrDefault(t => t.Id == id);
                    if (p != null)
                    {
                        p.Name = model.Name;
                    }
                }
            }
        }

        [ObservableProperty]
        private int menuCount;

        [ObservableProperty]
        private List<MenuSelect> menuList;

        [RelayCommand]
        private void SelectMenuItem(object parameter)
        {
            MenuCount = MenuList.Count(i => i.IsSelected == true);
        }

        [RelayCommand]
        private void PlaceOrder(object parameter)
        {
            var selectedMenuNameList = this.MenuList.Where(i => i.IsSelected == true).Select(i => i.Menu.Name).ToList();
            IDataService s = new XmlDataService();
            s.PlaceOrder(selectedMenuNameList);
            MessageBox.Show("订餐成功");
        }
        #endregion

        #region  多Language相关
        [RelayCommand]
        void ChooseLanguage(string language)
        {
            //英文
            if (language == "en")
            {
                App.Language = "en-US";
            }
            //中文
            else if (language == "zh")
            {
                App.Language = "zh-CN";
            }
        }
        #endregion

        #region Frame 导航框架 相关
        public void Button_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("aa");
            //frame.Source = new Uri("Pages/Page2.xaml", UriKind.Relative);
        }
        [RelayCommand]
        public void Button_Click(object sender)
        {
            var frame = sender as Frame;
            frame.Source = new Uri("Pages/Page2.xaml", UriKind.Relative);
        }
        #endregion

        #region TextBox 相关
        [ObservableProperty]
        private double textValue;
        #endregion

        #region 事件转命令执行
        public List<ComboBoxItemModel<Person>> ListCombox { get; set; }

        [ObservableProperty]
        private Person selectedCombox;

        [ObservableProperty]
        private String selectInfo;

        [RelayCommand]
        private void Select(int age)
        {
            SelectInfo = age.ToString();
        }
        #endregion

        #region 拖拽上传 - 传递原事件的参数
        [ObservableProperty]
        private string fileUrl;

        [RelayCommand]
        private void Drop(DragEventArgs e)
        {
            FileUrl = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(0).ToString();
        }

        #endregion

        #region 按钮传参
        [ObservableProperty]
        private Student retStudent;

        [RelayCommand]
        void SendStudent(Student student)
        {
            RetStudent = student;
        }
        #endregion

        #region Tag属性 相关
        private Assembly _assembly = Assembly.GetExecutingAssembly();

        public void Tag_Click(object sender, RoutedEventArgs e)
        {
            string winName = ((Button)e.OriginalSource).Tag.ToString();
            System.Windows.Window win = ((System.Windows.Window)_assembly.CreateInstance(string.Format("CommunityToolkitMvvmDemo.UserControls.{0}", winName)));
            win.Owner = Me;
            win.Show();
        }
        #endregion

        #region 验证相关

        [ObservableProperty]
        public string userName;

        [ObservableProperty]
        public int userAge;

        [ObservableProperty]
        public string userEmail;

        private string userNameNotNull;
        /// <summary>
        /// 用户名称（不为空）
        /// </summary>
        public string UserNameNotNull
        {
            get
            {
                return userNameNotNull;
            }
            set
            {
                SetProperty(ref userNameNotNull, value);

                if (string.IsNullOrEmpty(value))
                {
                    throw new ApplicationException("该字段不能为空");
                }
            }
        }



        [ObservableProperty]
        public int min =1;

        [ObservableProperty]
        public int max =5;

        [RelayCommand]
        public void TextBoxLostFocus()
        {
            Me.customGroup.CommitEdit();
        }


        #endregion

        #region Dialog  对话框
        [RelayCommand]
        private async void ShowDialog1()
        {
            //HandyControl.Controls.Dialog.Show("提交成功");
            var d = HandyControl.Controls.Dialog.Show(new Dialog1());
            await Task.Delay(2000);
            d.Close();
        }

        [RelayCommand]
        private void ShowDialog2()
        {
            HandyControl.Controls.Dialog.Show(new Dialog1(), "myToken");
        }
        #endregion

        #region Growl 消息通知

        [RelayCommand]
        private void Message1()
        {
            HandyControl.Controls.Growl.Success("消息通知1");
        }
        [RelayCommand]
        private void Message2()
        {
            HandyControl.Controls.Growl.Success("消息通知2", "SuccessMsg");
        }
        [RelayCommand]
        private void Message3()
        {
            HandyControl.Controls.Growl.Success(new GrowlInfo()
            {
                Message = "消息通知3",
                Token = "SuccessMsg",
                ShowCloseButton = true,
                ShowDateTime = true
            });
        }
        [RelayCommand]
        private void Message4()
        {

            HandyControl.Controls.Growl.Ask("确定要显示吗？", isConfirmed =>
            {
                if (isConfirmed)
                {
                    HandyControl.Controls.Growl.Info("消息通知4");
                }
                else
                {
                    HandyControl.Controls.Growl.Clear("AskMsg");
                }
                return isConfirmed;

            }, "AskMsg");
        }
        [RelayCommand]
        private void Message5()
        {
            HandyControl.Controls.Growl.Warning("消息通知5", "WarningMsg");
        }

        #endregion

        #region 打开图片
        [RelayCommand]
        private void OpenImage()
        {
            var imgBrower = new HandyControl.Controls.ImageBrowser(new Uri(@"pack://application:,,,/Assets/Images/zfb.png"));
            imgBrower.Show();
        }
        #endregion

        #region 精灵相关
        [RelayCommand]
        private void Sprite()
        {
            HandyControl.Controls.Sprite.Show(new AppSprite());
        }
        #endregion

        #region 步骤相关
        [ObservableProperty]
        private int stepIndex = 0;
        [RelayCommand]
        private void PrevStep(object StepBar)
        {
            HC.StepBar bar = StepBar as HC.StepBar;
            bar.Prev();


            if (StepIndex == 0) return;
            StepIndex--;


        }
        [RelayCommand]
        private void NextStep(object StepBar)
        {
            HC.StepBar bar = StepBar as HC.StepBar;
            bar.Next();


            if (StepIndex == 3) return;
            StepIndex++;

        }

        [ObservableProperty]
        private ObservableCollection<StepModel> stepList;

        #endregion

        #region ToggBlock 切换块
        [RelayCommand]
        private void Change(object TBlock)
        {
            HC.ToggleBlock tb = TBlock as HC.ToggleBlock;
            tb.IsChecked = !tb.IsChecked;

        }
        [RelayCommand]
        private void Change1(object TBlock)
        {
            HC.ToggleBlock tb = TBlock as HC.ToggleBlock;
            tb.IsChecked = null;

        }
        #endregion

        #region Pagination  页码条控件
        [ObservableProperty]
        private ObservableCollection<Person> personsPage;

        [ObservableProperty]
        private int pageIndex = 0;

        [ObservableProperty]
        private int pageCount = 0;

        [ObservableProperty]
        private int countPerPage = 5;

        [RelayCommand]
        private void PageUpdated()
        {
            var list = Persons.Skip((PageIndex - 1) * CountPerPage).Take(CountPerPage).ToList();
            if (PersonsPage != null && PersonsPage.Count > 0)
            {
                PersonsPage.Clear();
            }
            foreach (var person in list)
            {
                PersonsPage.Add(person);
            }
        }
        #endregion

        #region 进度条
        [ObservableProperty]
        private int progressValue = 0;

        [RelayCommand]
        private void BtuuonProgress()
        {
            Task.Run(async () =>
            {
                await Task.Delay(1000);
                ProgressValue += 20;
                await Task.Delay(1000);
                ProgressValue += 30;
                await Task.Delay(1000);
                ProgressValue += 25;
                await Task.Delay(1000);
                ProgressValue += 25;
            });
        }

        #endregion

        #region MessageBox 消息对话框
        [RelayCommand]
        private void MessageDialog()
        {
            HandyControl.Controls.MessageBox.Show("提交消息成功",
                "成功提示",
                MessageBoxButton.OK,
                MessageBoxImage.Information,
                MessageBoxResult.OK);

            HandyControl.Controls.MessageBox.Success("提交消息成功", "成功提示");
            HandyControl.Controls.MessageBox.Error("提交消息成功", "成功提示");
            HandyControl.Controls.MessageBox.Info("提交消息成功", "成功提示");
            HandyControl.Controls.MessageBox.Warning("提交消息成功", "成功提示");
            HandyControl.Controls.MessageBox.Fatal("提交消息成功", "成功提示");

            var ret = HandyControl.Controls.MessageBox.Ask("提交消息成功?", "成功提示");
            if (ret == MessageBoxResult.OK)
            {
                HandyControl.Controls.MessageBox.Success("!!!!!成功", "成功提示");
            }
        }
        #endregion
        #region Notification  桌面通知

        [RelayCommand]
        private void NotificationDialog()
        {
            HC.Notification.Show("这是一个 桌面通知消息", ShowAnimation.Fade, false);

            HC.Notification.Show(new NotificationWindow(), ShowAnimation.Fade, true);
        }
        #endregion
        #region Notification  托盘图标
        [RelayCommand]
        private void ShowBalloonTip()
        {
            HC.NotifyIcon.ShowBalloonTip("提示", "气泡信息", NotifyIconInfoType.Info, "hc");
        }
        #endregion
        #region SearchBar 搜索框
        [RelayCommand]
        private void SearchBar(string str)
        {

        }

        #endregion


        #region 封面流相关
        HandyControlWindow? Me;
        #endregion

        #region 按钮相关
        [ObservableProperty]
        private NavigationBarModel menuModel;

        [ObservableProperty]
        private ObservableCollection<NavigationBarModel> menuModels;

        [RelayCommand]
        private void NavigationBar(NavigationBarModel model)
        {
            MenuModel = model;
            MessageBox.Show(MenuModel.Title);
        }

        #endregion

        #region CommunityToolkitMvvm 命令相关
        // -------属性完整写法
        ////private string? _title ="Hello world";
        ////public string Title   
        ////{
        ////    get => _title??"111";

        ////    //set  {
        ////    //    if (value != _title)
        ////    //    {
        ////    //        _title = value;
        ////    //        OnPropertyChanged();
        ////    //    }
        ////    //}

        ////    set => SetProperty(ref _title, value);
        ////}

        // -------属性简写1
        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(Caption))] // 字段 Title 更改时，会自动通知另一个字段 Caption，则需要在 Title 字段上添加特性NotifyPropertyChangedFor
        private string? _title = "Hello world";
        public string Caption => $"Title: {Title}";


        // -------属性简写2
        //private bool _isEnabled = false;
        //public bool IsEnabled
        //{
        //    get => _isEnabled;
        //    set
        //    {
        //        SetProperty(ref _isEnabled, value);
        //        ButtonCmd.NotifyCanExecuteChanged();  // NotifyCanExecuteChanged方法来引发CanExeCutechanged事件。
        //    }
        //}


        [ObservableProperty]
        [NotifyCanExecuteChangedFor(nameof(ButtonClickCommand))] // 假设某个命令的执行状态依赖 IsEnabled 字段，则每当 IsEnabled 值改变时，需通知命令进行重新计算状态
        private bool _isEnabled = false;


        // -------命令完整写法
        //public RelayCommand ButtonCmd { get; set; } = null;
        //public CommunityToolkitMvvmWindowViewModel()
        //{
        //    //ButtonCmd = new RelayCommand(() => { Debug.WriteLine("Button Clicked! "); });  
        //   ButtonCmd = new RelayCommand(() => { Title = "GoodBye"; }, () => IsEnabled);
        //}


        [ObservableProperty]
        string jsonStr;

        private bool CanButtonClick() => IsEnabled;

        // -------命令简写
        [RelayCommand(CanExecute = nameof(CanButtonClick))]  // CanExecute 用法
        private async Task ButtonClickAsync()   // 异步方法
        {
            await Task.Delay(2000);
            Title = "GoodBye";

            // -------发消息场景
            //var rec1 = new Receiver1ViewModel();
            //rec1.Number = 55;
            //rec1.Number = 555;
            //WeakReferenceMessenger.Default.Send(new StringMessage("hello message !!!"));
            //WeakReferenceMessenger.Default.Send(new ValueChangedMessage<string>("hello message !!!!!!"));

            //var res1 = WeakReferenceMessenger.Default.Send(new RequestMessage<string>());
            //Debug.WriteLine(res1.Response.ToString());

            var rec2 = new Receiver2ViewModel();
            rec2.IsActive = true; // 开启 接收信息功能
            var res2 = WeakReferenceMessenger.Default.Send(new RequestMessage<string>());
            Debug.WriteLine(res2.Response.ToString());

            // -------序列化的场景
            var vm = new SerializeViewModel() { Name = "John", Age = 20, Guid = Guid.NewGuid() };
            JsonStr = JsonSerializer.Serialize(vm);
        }

        // -------使用第三方类的场景
        public StudentViewModel stuViewModel { get; private set; } = new StudentViewModel(new Models.Student() { Name = "Tom", Age = 18, Address = "Street 10001#" });
        public Student stuModel { get; private set; } = new Student() { Name = "Tom", Age = 18, Address = "Street 10001#" };
        [RelayCommand]
        void ChangeName()
        {
            stuViewModel.Name = "John";
            stuModel.Name = "John";
        }


        // -------SetPropertyAndNotifyOnCompletion 方法的使用，可以将Task直接包装成属性，并且能在任务完成后触发通知事件
        [ObservableProperty]
        private string desc = "hello 123";

        private TaskNotifier? changeDescTask; // TaskNotifier 对Task 进行包装，可以让task 属性通知前台
        public Task? ChangeDescTask
        {
            get => changeDescTask;
            set => SetPropertyAndNotifyOnCompletion(ref changeDescTask, value);
        }
        [RelayCommand]
        void ChangeDescMethod()
        {
            //ChangeDescTask = Task.Delay(2000).ContinueWith(Task => Desc = "wold 123");
            ChangeDescTask = Task.Delay(2000).ContinueWith(_ => Desc = "hello 456");
        }



        // ------- 命令是否执行，可以不用写 CanFooExecute 方法
        [ObservableProperty]
        [NotifyCanExecuteChangedFor(nameof(FooCancelCommand))]
        [NotifyCanExecuteChangedFor(nameof(Foo1Command))]
        [NotifyCanExecuteChangedFor(nameof(Foo2Command))]
        [NotifyCanExecuteChangedFor(nameof(Foo3Command))]
        [NotifyCanExecuteChangedFor(nameof(Foo4Command))]
        private bool isActive;

        bool CanFooExecute() => IsActive;
        [RelayCommand(CanExecute = nameof(IsActive))]
        void FooCancel()
        {
            IsActive = false;
        }

        //-----AllowConcurrentExecutions = true  点击后，2s 内按钮不变灰
        [ObservableProperty]
        private string message = "hello";

        [RelayCommand(CanExecute = nameof(IsActive), AllowConcurrentExecutions = true)]
        async Task Foo1Async()
        {
            await Task.Delay(2000);
            Message += "+w";
        }



        //-----IncludeCancelCommand 用法，命令取消，会生成 Foo2CancelCommand 方法
        [RelayCommand(CanExecute = nameof(IsActive), IncludeCancelCommand = true)]
        async Task Foo2Async(CancellationToken token)
        {
            try
            {
                await Task.Delay(2000, token);
                Message += "+w";
            }
            catch (OperationCanceledException)
            {
            }
        }


        //-----命令取消，由于ContinueWith 原因，会继续执行 
        [RelayCommand(CanExecute = nameof(IsActive), IncludeCancelCommand = true)]
        Task Foo3Async(CancellationToken token)
        {
            try
            {
                return Task.Delay(2000, token)
                    .ContinueWith(_ => Message += "+w");
            }
            catch (OperationCanceledException)
            {
                return Task.FromCanceled(token);
            }
        }

        //-----命令取消，可以判断t，不会继续执行 
        [RelayCommand(CanExecute = nameof(IsActive), IncludeCancelCommand = true)]
        Task Foo4Async(CancellationToken token)
        {
            try
            {
                return Task.Delay(2000, token)
                    .ContinueWith(t =>
                    {
                        if (t.IsCompletedSuccessfully) // 没有取消，是 IsCompletedSuccessfully
                            Message += "+w";
                        if (t.IsCanceled)  // 取消后，是 IsCanceled
                            Message += "-w";
                    });
            }
            catch (OperationCanceledException)
            {
                return Task.FromCanceled(token);
            }
        }



        //----- ObservableCollection 用法
        private ObservableCollection<StudentViewModel> studentList;
        public ObservableCollection<StudentViewModel> StudentList { get => studentList; set => SetProperty(ref studentList, value); }

        private StudentViewModel studentselected;
        public StudentViewModel StudentSelected { get => studentselected; set => SetProperty(ref studentselected, value); }

        [RelayCommand]
        void Foo5()
        {
            var dbStudentList = new List<Student>();
            dbStudentList.Add(new Student() { Age = 85, Name = "相清" });
            dbStudentList.Add(new Student() { Age = 25, Name = "濮悦" });

            StudentList = new ObservableCollection<StudentViewModel>(dbStudentList.Select(x => new StudentViewModel(x)));
        }

        // ----- NotifyCanExecuteChanged 用法  
        private string inputText;
        public string InputText
        {
            get => inputText;
            set
            {
                SetProperty(ref inputText, value);
                Foo6Command.NotifyCanExecuteChanged();
            }
        }
        private bool CanShowMsgExecute() => !string.IsNullOrEmpty(InputText);

        [RelayCommand(CanExecute = nameof(CanShowMsgExecute))]
        void Foo6()
        {
            MessageBox.Show(InputText);
        }


        #endregion
        #region CommunityToolkitMvvm 消息相关
        //----- IMessenger
        record SimpleMessage(string Content);
        readonly static IMessenger messenger = WeakReferenceMessenger.Default;
        class Listener
        {
            public Listener(IMessenger messenger, Action<string> response)
            {
                messenger.Register<SimpleMessage>(this, (_, m) => response(m.Content));
            }
            public Listener(IMessenger messenger)
            {
                if (!messenger.IsRegistered<AsyncRequestMessage<string>>(this))
                {
                    messenger.Register<AsyncRequestMessage<string>>(this, (_, m) =>
                    {
                        //m.Reply(Task.Delay(2000).ContinueWith(_ => "hello"));
                        m.Reply(DoJobAsync());
                    });
                }

            }
            private async Task<string> DoJobAsync()
            {
                await Task.Delay(2000);
                return "reply message!!!";
            }
        }
        Listener l11 = new Listener(messenger, m => Debug.WriteLine($"l1 received: {m}"));
        Listener l12 = new Listener(messenger, m => Debug.WriteLine($"l2 received: {m}"));


        [RelayCommand]
        void Msg1()
        {
            messenger.Send(new SimpleMessage("msg1"));
            messenger.Send(new SimpleMessage("msg2"));
        }

        //----- IMessenger ，通过类型来区分消息
        class Listener<T>
        {
            public Listener(IMessenger messenger, Action<T> response)
            {
                messenger.Register<ValueChangedMessage<T>>(this, (_, m) => response(m.Value));
            }
        }
        Listener<string> l21 = new Listener<string>(messenger, m => Debug.WriteLine($"l1 received: {m}"));
        Listener<int> l22 = new Listener<int>(messenger, m => Debug.WriteLine($"l2 received: {m}"));

        [RelayCommand]
        void Msg2()
        {
            messenger.Send(new ValueChangedMessage<string>("hello"));
            messenger.Send(new ValueChangedMessage<string>("world"));
            messenger.Send(new ValueChangedMessage<int>(123));
            messenger.Send(new ValueChangedMessage<int>(456));
        }

        //----- IMessenger ，通过token 来区分消息
        class Listener2
        {
            public Listener2(IMessenger messenger, string chanel, Action<string> response)
            {
                messenger.Register<SimpleMessage, string>(this, chanel, (_, m) => response(m.Content));
            }
        }
        Listener2 l31 = new Listener2(messenger, "l1", m => Debug.WriteLine($"l1 received: {m}"));
        Listener2 l32 = new Listener2(messenger, "l2", m => Debug.WriteLine($"l2 received: {m}"));
        [RelayCommand]
        void Msg3()
        {
            messenger.Send(new SimpleMessage("l1 msg"), "l1");
            messenger.Send(new SimpleMessage("l2 msg"), "l2");
        }


        //----- AsyncRequestMessage 用法
        Listener l4 = new Listener(messenger);
        [RelayCommand]
        async Task Msg4()
        {
            var reply = messenger.Send(new AsyncRequestMessage<string>());
            var msg = await reply.Response;
            Debug.WriteLine(msg);
        }


        #endregion
 

        public void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Me = sender as HandyControlWindow;

            Me.CoverFlowMain.AddRange(new[]  {
                 new Uri(@"pack://application:,,,/Assets/Images/car1.png"),
                 new Uri(@"pack://application:,,,/Assets/Images/car2.png"),
                 new Uri(@"pack://application:,,,/Assets/Images/car3.png"),
             });
        }

        public HandyControlViewModel()
        {
            #region 步骤相关
            StepList = new ObservableCollection<StepModel>();
            StepList.Add(new StepModel("步骤", "登录1"));
            StepList.Add(new StepModel("步骤", "基本信息1"));
            StepList.Add(new StepModel("步骤", "上传头像1"));
            StepList.Add(new StepModel("步骤", "完成1"));

            #endregion

            #region 选项卡相关
            TabList = new ObservableCollection<TabModel>();
            TabList.Add(new TabModel("用户管理"));
            TabList.Add(new TabModel("角色管理"));
            TabList.Add(new TabModel("菜单管理"));
            TabList.Add(new TabModel("设备管理"));
            TabList.Add(new TabModel("日志管理"));
            TabList.Add(new TabModel("系统管理"));
            TabList.Add(new TabModel("接口管理"));
            TabList.Add(new TabModel("报表管理"));
            #endregion

            #region Tag标签
            TagList = new ObservableCollection<TagModel>();
            TagList.Add(new TagModel("A", "aaa", true));
            TagList.Add(new TagModel("B", "aaa", true));
            TagList.Add(new TagModel("C", "aaa", true));
            TagList.Add(new TagModel("D", "aaa", true));
            TagList.Add(new TagModel("E", "aaa", true));
            TagList.Add(new TagModel("F", "aaa", true));
            TagList.Add(new TagModel("G", "aaa", true));
            TagList.Add(new TagModel("H", "aaa", true));

            #endregion

            Persons = new ObservableCollection<Person>();
            PersonsPage = new ObservableCollection<Person>();
            Persons.Add(new Person() { Id = 1, Name = "John Doe", Age = 22, Mail = "john@doe-fa.com", LogoUrl = "/Assets/Images/car1.png", Logo = new BitmapImage(new Uri("/Assets/Images/car1.png", UriKind.Relative)), Sex = SexType.Male, IsEnabled = true, SelectedValue = "Kea", SelectionSource = new List<string>() { "Kea", "Lau", "Nuh" } });
            Persons.Add(new Person() { Id = 2, Name = "Sammy Doe", Age = 11, Mail = "sammy.doe@g.com", LogoUrl = "/Assets/Images/car2.png", Logo = new BitmapImage(new Uri("/Assets/Images/car2.png", UriKind.Relative)), Sex = SexType.Male, IsEnabled = false, SelectedValue = "invalid", SelectionSource = new List<string>() { "invalid", "valid" } });
            Persons.Add(new Person() { Id = 3, Name = "John Doe", Age = 22, Mail = "john@doe-fa.com", LogoUrl = "/Assets/Images/car3.png", Logo = new BitmapImage(new Uri("/Assets/Images/car3.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = true, SelectedValue = "5", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 4, Name = "Jane Doe", Age = 39, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/car4.png", Logo = new BitmapImage(new Uri("/Assets/Images/car4.png", UriKind.Relative)), Sex = SexType.Male, IsEnabled = false, SelectedValue = "3", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 5, Name = "xcz1", Age = 11, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/car5.png", Logo = new BitmapImage(new Uri("/Assets/Images/car5.png", UriKind.Relative)), Sex = SexType.Male, IsEnabled = true, SelectedValue = "5", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 6, Name = "xcz2", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 7, Name = "xcz3", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 8, Name = "xcz4", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 9, Name = "xcz5", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = true, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 10, Name = "xcz6", Age = 11, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/car5.png", Logo = new BitmapImage(new Uri("/Assets/Images/car5.png", UriKind.Relative)), Sex = SexType.Male, IsEnabled = false, SelectedValue = "5", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 11, Name = "xcz7", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 12, Name = "xcz8", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = true, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 13, Name = "xcz9", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 14, Name = "xcz10", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = true, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 15, Name = "xcz11", Age = 11, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/car5.png", Logo = new BitmapImage(new Uri("/Assets/Images/car5.png", UriKind.Relative)), Sex = SexType.Male, IsEnabled = true, SelectedValue = "5", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 16, Name = "xcz12", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 17, Name = "xcz13", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = false, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 18, Name = "xcz14", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = true, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });
            Persons.Add(new Person() { Id = 19, Name = "xcz15", Age = 22, Mail = "jane@doe-fa.com", LogoUrl = "/Assets/Images/zfb.png", Logo = new BitmapImage(new Uri("/Assets/Images/zfb.png", UriKind.Relative)), Sex = SexType.Female, IsEnabled = true, SelectedValue = "6", SelectionSource = new List<string>() { "0", "1", "2", "3", "4", "5", "6" } });

            #region  Pagination  页码条控件
            var totalCount = Persons.Count();
            if (totalCount % CountPerPage > 0)
            {
                PageCount = totalCount / CountPerPage + 1;
            }
            else
            {
                PageCount = totalCount / CountPerPage;
            }

            var list = Persons.Skip((PageIndex - 1) * CountPerPage).Take(CountPerPage).ToList();
            if (PersonsPage != null && PersonsPage.Count > 0)
            {
                PersonsPage.Clear();
            }
            foreach (var person in list)
            {
                PersonsPage.Add(person);
            }
            #endregion

            #region 图表相关
            Labels = new[] { "中国", "美国", "澳大利亚", "日志" };

            SeriesCollection = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title="2015",
                    Values = new ChartValues<double> { 3, 5, 7, 4 },
                    LabelPoint = point => point.Y + "K",
                    DataLabels = true,
                },
                 new ColumnSeries
                {
                     Title="2016",
                     Values = new ChartValues<decimal> { 5, 6, 2, 7 },
                     LabelPoint = point => point.Y + "K",
                     DataLabels = true,
                },
                 new ColumnSeries
                 {
                     Title="2017",
                     Values=new ChartValues<decimal>{1,2,3,4},
                     LabelPoint = point => point.Y + "K",
                     DataLabels = true,
                 }
            };


            Values1 = new ChartValues<double>();
            Values2 = new ChartValues<double>();
            XLabels = new ObservableCollection<string>();

            Random random = new Random();

            Task.Factory.StartNew(async () =>
            {
                while (true)
                {
                    await Task.Delay(2000);
                    Values1.Add(random.Next(10, 80));
                    Values2.Add(random.Next(10, 90));
                    XLabels.Add(DateTime.Now.ToString("mm:ss"));

                    if (Values1.Count > 50)
                    {
                        Values1.RemoveAt(0);
                        Values2.RemoveAt(0);
                        XLabels.RemoveAt(0);
                    }

                }
            });
            #endregion

            #region Combox相关
            var source = new Dictionary<int, string>();

            foreach (var item in Enum.GetValues(typeof(EnumType)))
            {
                source.Add((int)(EnumType)Enum.Parse(typeof(EnumType), item.ToString()), item.ToString());
            }
            ComboxKYs = source;

            ComboxClass = new ObservableCollection<EnumTypeClass>();
            foreach (var item in Enum.GetValues(typeof(EnumType)))
            {
                ComboxClass.Add(new EnumTypeClass() { ItemType = (EnumType)Enum.Parse(typeof(EnumType), item.ToString()) });
            }

            ComboxPersons = new List<ComboBoxItemModel<Person>>
            {
                new ComboBoxItemModel<Person>{Description="Item0",SelectedModel=new Person{ Name="张三",Age=10 },IsEnable=true},
                new ComboBoxItemModel<Person>{Description="Item1",SelectedModel=new Person{ Name="李四",Age=28 },IsEnable=false},
                new ComboBoxItemModel<Person>{Description="Item2",SelectedModel=new Person{ Name="赵五",Age=77 },IsEnable=true},
                new ComboBoxItemModel<Person>{Description="Item3",SelectedModel=new Person{ Name="孙六",Age=44 },IsEnable=false},
                new ComboBoxItemModel<Person>{Description="Item4",SelectedModel=new Person{ Name="王七",Age=55 },IsEnable=true},
            };

            PersonList.Add(new Person { Id = 1, Name = "aa1" });
            PersonList.Add(new Person { Id = 2, Name = "aa2" });
            PersonList.Add(new Person { Id = 3, Name = "aa3" });
            PersonList.Add(new Person { Id = 4, Name = "a1" });
            PersonList.Add(new Person { Id = 5, Name = "a2" });
            PersonList.Add(new Person { Id = 6, Name = "b" });
            PersonList.Add(new Person { Id = 7, Name = "bb1" });
            PersonList.Add(new Person { Id = 8, Name = "bb2" });
            PersonList.Add(new Person { Id = 9, Name = "c" });
            #endregion

            #region ItemsControl 相关
            ItemList = new ObservableCollection<TabBaseViewModel>();
            ItemList.Add(new TabBaseViewModel() { TabHead = "设备1", TabBody = "状态1" });
            ItemList.Add(new TabBaseViewModel() { TabHead = "设备2", TabBody = "状态2", TabMessage = "消息2" });
            ItemList.Add(new Tab1ViewModel() { TabHead = "设备3", TabBody = "状态3", TabMessage = "消息3" });

            RadioButtonList = new List<RadioButtons>()
            {
                 new RadioButtons(){ Content="苹果", IsCheck = false },
                 new RadioButtons(){ Content="香蕉", IsCheck = false },
                 new RadioButtons(){ Content="梨", IsCheck = false },
                 new RadioButtons(){ Content="樱桃", IsCheck = false },
            };

            CheckButtonsList = new List<CheckButtons>()
            {
                 new CheckButtons(){ Content="苹果", IsCheck = false },
                 new CheckButtons(){ Content="香蕉", IsCheck = false },
                 new CheckButtons(){ Content="梨", IsCheck = false },
                 new CheckButtons(){ Content="樱桃", IsCheck = false }
            };

            #endregion

            #region 树相关
            TreeInfo = new List<TreeNode>()
            {
                new TreeNode(){
                  NodeID = "1", NodeName = "苹果",Children=new List<TreeNode>(){
                    new TreeNode(){ NodeID="1.1", NodeName ="苹果A" },
                    new TreeNode(){ NodeID="1.2", NodeName ="苹果B" },
                    new TreeNode(){ NodeID="1.3", NodeName ="苹果C", Children = new List<TreeNode>(){
                       new TreeNode(){ NodeID="1.3.1", NodeName ="苹果C1" },
                       new TreeNode(){ NodeID="1.3.2", NodeName ="苹果C2" },
                    } }
                  }
                },
                new TreeNode(){
                  NodeID = "2", NodeName = "香蕉",Children=new List<TreeNode>(){
                    new TreeNode(){ NodeID="2.1", NodeName ="香蕉A" },
                    new TreeNode(){ NodeID="2.2", NodeName ="香蕉B" },
                    new TreeNode(){ NodeID="2.3", NodeName ="香蕉C" }
                  }
                }
            };
            #endregion

            #region ListView 相关
            // 分组
            PersonListGroupView = new ListCollectionView(Persons);
            PropertyGroupDescription groupDescription = new PropertyGroupDescription("Age");
            PersonListGroupView.GroupDescriptions.Add(groupDescription);

            // 排序
            PersonListSortView = new ListCollectionView(Persons);
            PersonListSortView.SortDescriptions.Add(new SortDescription("Age", ListSortDirection.Ascending));
            PersonListSortView.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Descending));

            // 排序 - 两种方法
            personListSortView111 = new ListCollectionView(Persons);
            PersonListSortView222 = CollectionViewSource.GetDefaultView(Persons);

            // 过滤
            PersonListView = new ListCollectionView(Persons);
            PersonListView.Filter = Filter;
            #endregion

            #region DataGrid
            MenuCount = -1;

            IDataService s = new XmlDataService();
            var menus = s.GetAllData();
            MenuList = new List<MenuSelect>();
            foreach (var item in menus)
            {
                MenuSelect m = new MenuSelect();
                m.Menu = item;
                m.IsSelected = false;
                MenuList.Add(m);
            }
            #endregion

            #region TextBox 相关
            textValue = 0.00;
            #endregion

            #region 事件转命令执行
            ListCombox = new List<ComboBoxItemModel<Person>>
            {
                new ComboBoxItemModel<Person>{Description="Item3",SelectedModel=new Person{ Name="张三",Age=3 },IsEnable=true},
                new ComboBoxItemModel<Person>{Description="Item4",SelectedModel=new Person{ Name="李四",Age=4 },IsEnable=false},
                new ComboBoxItemModel<Person>{Description="Item5",SelectedModel=new Person{ Name="赵五",Age=5 },IsEnable=true},
                new ComboBoxItemModel<Person>{Description="Item6",SelectedModel=new Person{ Name="孙六",Age=6 },IsEnable=false},
                new ComboBoxItemModel<Person>{Description="Item7",SelectedModel=new Person{ Name="王七",Age=7 },IsEnable=true},
            };

            #endregion


            #region 按钮相关
            MenuModels = new ObservableCollection<NavigationBarModel>();
            menuModels.Add(new NavigationBarModel() { IconFont = "\xe60c", Title = "我的一天",   Display = false });
            menuModels.Add(new NavigationBarModel() { IconFont = "\xe695", Title = "重要"  });
            menuModels.Add(new NavigationBarModel() { IconFont = "\xe80a", Title = "已计划日程" });
            menuModels.Add(new NavigationBarModel() { IconFont = "\xe74a", Title = "已分配给我"  });
            menuModels.Add(new NavigationBarModel() { IconFont = "\xe614", Title = "任务"  });

            MenuModel = MenuModels[1];

            #endregion
        }


    }
}
